﻿<UserControl x:Class="AutomationMLMapper.Controls.SystemUnitClassListControl"
			 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
			 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
			 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:system="clr-namespace:System;assembly=mscorlib"
			 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
			 xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
			 xmlns:local="clr-namespace:AutomationMLMapper.Controls"
             xmlns:MarkupExtensions="clr-namespace:AutomationMLMapper.Controls.MarkupExtensions"
			 xmlns:ConvertersAndTemplateSelectors="clr-namespace:AutomationMLMapper.Controls.ConvertersAndTemplateSelectors"
			 xmlns:Properties="clr-namespace:AutomationMLMapper.Properties" mc:Ignorable="d" 
			 d:DesignHeight="400" d:DesignWidth="600">
	<UserControl.Resources>
		<ResourceDictionary>
			<ResourceDictionary.MergedDictionaries>
				<ResourceDictionary Source="/AutomationMLMapper;component/StyleResources/ListStyle.xaml"/>
				<ResourceDictionary Source="/AutomationMLMapper;component/StyleResources/Templates.xaml"/>
			</ResourceDictionary.MergedDictionaries>
			<ConvertersAndTemplateSelectors:BoolToVisibilityConverter FalseValue="Collapsed" x:Key="btvc" />
		</ResourceDictionary>      
	</UserControl.Resources>
	<Grid Background="Transparent">
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
			<RowDefinition Height="*"></RowDefinition>			
		</Grid.RowDefinitions>

		<Grid.InputBindings>
			<KeyBinding Command="{Binding ClassesCollection.DeleteCommand}"  Gesture="Delete"/>
			<KeyBinding Command="{Binding ClassesCollection.AddCommand}"  Gesture="Add"/>
			<KeyBinding Command="{Binding LoadSystemCommand}" Gesture="Ctrl+S"/>
			<KeyBinding Command="{Binding ImportRoleLibsCommand}" Gesture="Ctrl+R"/>
		</Grid.InputBindings>
		
		<Border Margin="1"  Grid.Row="0" BorderThickness="1" CornerRadius="1" BorderBrush="#FF565656">
			<Grid Margin="1">
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto"></ColumnDefinition>
					<ColumnDefinition Width="*"></ColumnDefinition>
					<ColumnDefinition Width="Auto"></ColumnDefinition>
					<ColumnDefinition Width="Auto"></ColumnDefinition>
				</Grid.ColumnDefinitions>

				<TextBlock Grid.Column="0"  FontWeight="Bold" Margin="5,0,5,0" VerticalAlignment="Center">                                             
					<Run Text="Name of the "/>
					<Run Text="{Binding Path=SystemType}"/>
				</TextBlock>
				
				<AdornerDecorator Grid.Column="1">
					<TextBox  Style="{StaticResource ValidationTextBox}" Margin="0,0,5,0" 
                              Text="{Binding Path=Name, UpdateSourceTrigger=LostFocus,
							 ValidatesOnDataErrors=true, NotifyOnValidationError=true}" VerticalAlignment="Center" 
							 ToolTip="{x:Static Properties:Resources.SystemnameToolTip}">
					</TextBox>
				</AdornerDecorator>

                <ribbon:RibbonButton Grid.Column="2" Height="42"
									LargeImageSource="{MarkupExtensions:ImageResolution Source=SCLib.ico, Size=32}"
                                    Command="{Binding LoadSystemCommand}"
									ToolTipImageSource="/AutomationMLMapper;component/Images/Info.ico"
									ToolTipDescription="{x:Static Properties:Resources.SystemDefinitionAutomationMLDocumentDescription}" 
									ToolTipTitle="{x:Static Properties:Resources.SystemDefinitionAutomationMLDocument}">
                </ribbon:RibbonButton>

				<ribbon:RibbonButton Grid.Column="3" Height="42" LargeImageSource="{MarkupExtensions:ImageResolution Source=RCLib.ico, Size=32}" 
                                     Command="{Binding ImportRoleLibsCommand}" KeyTip="R"                                     
									 ToolTipTitle="RoleClass Libraries AutomationML Document (Ctrl+R)" 
									 ToolTipImageSource="/AutomationMLMapper;component/Images/Info.ico"
									 ToolTipDescription="Load RoleClass Libraries from an external AutomationML-Document. The RoleClass Libraries and its external references are merged into the SystemDefinition AutomationML-Document" 
									>
				</ribbon:RibbonButton>
			</Grid>
		</Border>

        <Grid Background="#FFD4D4D4" Grid.Row="1"  >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"></ColumnDefinition>
                <ColumnDefinition Width="Auto"></ColumnDefinition>
            </Grid.ColumnDefinitions>
			<TextBlock  Style="{StaticResource HeaderTextBlock}" Grid.Column="0" 
                        Text="{x:Static Properties:Resources.ListOfSystemUnitClasses}"></TextBlock>
			<DockPanel Grid.Column="1">

				<local:AddDeleteItemControl DockPanel.Dock="Right"
											ButtonAddToolTip="Add a SystemUnit Class"
											ButtonAddToolTipDescription="A SystemUnitClass is added to the actual SystemUnitClassLib describing the System - identified with the shown Systemname. Each SystemUnitClass should at least have one SupportedRoleClass assigned to it."
											ButtonAddCommand="{Binding ClassesCollection.AddCommand}"
											ButtonDeleteCommand="{Binding ClassesCollection.DeleteCommand}"
											ButtonDeleteToolTip="Delete the selected class"
											ButtonDeleteToolTipDescription="The Class and all its assignments are removed from the SystemUnitClassLib">
				</local:AddDeleteItemControl>
				
				

			</DockPanel>
		</Grid>

		<ListView x:Name="ListOfSimulatedClasses" Grid.Row="2" 
                  IsSynchronizedWithCurrentItem="True" 
                  ScrollViewer.CanContentScroll="True"
                  HorizontalAlignment="Stretch"
                  VirtualizingStackPanel.IsVirtualizing="True"
                  VirtualizingStackPanel.VirtualizationMode="Recycling"
                  ScrollViewer.IsDeferredScrollingEnabled="True"
				  DataContext="{Binding ClassesCollection}"                 
				  ItemsSource="{Binding RelativeSource={RelativeSource Self}, Path=DataContext.View}">

			<ListView.View>
				<GridView>
                    <GridViewColumn CellTemplate="{StaticResource SystemUnitClassTemplate}"  
                                    HeaderContainerStyle="{StaticResource ColumnHeaderStyle}">
						<GridViewColumn.HeaderTemplate>
							<DataTemplate>                                
								<StackPanel Orientation="Horizontal">
                                    <Image Source="{MarkupExtensions:ImageResolution Source=SC.ico, Size=24}"></Image>
									<TextBlock VerticalAlignment="Center" Margin="5,0,0,0" Text="SystemUnitClass"></TextBlock>
								</StackPanel>
							</DataTemplate>
						</GridViewColumn.HeaderTemplate>
					</GridViewColumn>
                    
					<GridViewColumn Width="Auto" x:Name="SupportedRolesColumn" HeaderContainerStyle="{StaticResource ColumnHeaderStyle}">
						<GridViewColumn.HeaderTemplate>
							<DataTemplate>                               
								<local:CollapsibleColumnHeader HeaderImageSource="{MarkupExtensions:ImageResolution Source=SRC.ico, Size=16}"
															   ShowColumn="{Binding ElementName=ListOfSimulatedClasses, Mode=TwoWay, 
																			  Path=DataContext.ShowSupportedRoles}"
															   HeaderToolTip="Show Supported Roles of the SystemUnitClass" HeaderName="Supported RoleClass" 
															   ExpandColumn="{Binding ElementName=ListOfSimulatedClasses, Mode=TwoWay, 
																			  Path=DataContext.ExpandSupportedRoles}"
															   Column="{Binding ElementName=SupportedRolesColumn}">
								</local:CollapsibleColumnHeader> 
							</DataTemplate>
						</GridViewColumn.HeaderTemplate>
					   
						<GridViewColumn.CellTemplate>
							<DataTemplate>                                
								<local:CAEXCollectionView DataContext="{Binding RolesCollection}" 
														  AllowEditElement ="False"
														  AddToolTipDescription="To add a supported-RoleClass, please select a RoleClass from any RoleClass-Library which has not yet been assigned to the SystemUnitClass"
														  DeleteToolTipDescription="The selected Supported RoleClass is removed from the SystemUnitClass to which it is assigned to"
														  Visibility="{Binding ElementName=ListOfSimulatedClasses,
														  Path=DataContext.ShowSupportedRoles, Converter={StaticResource btvc}}"/> 
							</DataTemplate>
						</GridViewColumn.CellTemplate>
					</GridViewColumn>

					<GridViewColumn x:Name="ClassAttributesColumn" Width="Auto" HeaderContainerStyle="{StaticResource ColumnHeaderStyle}">
						<GridViewColumn.HeaderTemplate>                           
								<DataTemplate>
                                <local:CollapsibleColumnHeader HeaderImageSource="{MarkupExtensions:ImageResolution Source=AT.ico, Size=16}"
																   ShowColumn="{Binding ElementName=ListOfSimulatedClasses, Mode=TwoWay, 
																				Path=DataContext.ShowClassAttributes}"
																   ExpandColumn="{Binding ElementName=ListOfSimulatedClasses, Mode=TwoWay, 
																				Path=DataContext.ExpandClassAttributes}"
																   HeaderToolTip="Show Attributes of the SystemUnitClass"
																   HeaderName="Attributes" Column="{Binding ElementName=ClassAttributesColumn}">
									</local:CollapsibleColumnHeader>
								</DataTemplate> 
						</GridViewColumn.HeaderTemplate>
						<GridViewColumn.CellTemplate>
							<DataTemplate>
								<local:CAEXCollectionView 
													 Visibility="{Binding ElementName=ListOfSimulatedClasses, 
													 Path=DataContext.ShowClassAttributes, Converter={StaticResource btvc}}"
													 AddToolTipDescription="An attribute is added and assigned to the SystemUnitClass. All Attributenames of all attributes, assigned to the same SystemUnitClass have to be unique"
													 DeleteToolTipDescription="The Selected Attribute is removed from the SystemUnitClass to which it is assigned to"
													 DataContext="{Binding AttributesCollection}"/>
							</DataTemplate>
						</GridViewColumn.CellTemplate>                       
					</GridViewColumn>

					<GridViewColumn x:Name="PropertySetColumn" Width="Auto" HeaderContainerStyle="{StaticResource ColumnHeaderStyle}">
						<GridViewColumn.HeaderTemplate>
							<DataTemplate>
								<local:CollapsibleColumnHeader HeaderImageSource="/AutomationMLMapper;component/Images/IE.ico"
															   ShowColumn="{Binding ElementName=ListOfSimulatedClasses, Mode=TwoWay, 
																					Path=DataContext.ShowPropertySets}"                                                               
															   ExpandColumn="{Binding ElementName=ListOfSimulatedClasses, Mode=TwoWay, 
																			  Path=DataContext.ExpandPropertySets}"
															   HeaderToolTip="Show PropertySets of the SystemUnitClass" 
															   HeaderName="PropertySets" Column="{Binding ElementName=PropertySetColumn}">
								</local:CollapsibleColumnHeader>                                
							</DataTemplate>
						</GridViewColumn.HeaderTemplate>
					   
						<GridViewColumn.CellTemplate>
							<DataTemplate>
								<local:CAEXCollectionView 
									Visibility="{Binding ElementName=ListOfSimulatedClasses, Path=DataContext.ShowPropertySets, Converter={StaticResource btvc}}"                                     
									AddToolTipDescription="To add a PropertySet, please select a RoleClass from a RoleClass-Library which contains RoleClasses, derived from the AUtomationML-BaseRoleClass 'PropertySet'. Please ensure, that the RoleClass has assigned Attributes"
									DeleteToolTipDescription="The selected PropertySet is removed from the SystemUnitClass to which it is assigned to"
									DataContext="{Binding PropertySetCollection}"/>
							</DataTemplate>
						</GridViewColumn.CellTemplate>
					</GridViewColumn>

				</GridView>
			</ListView.View>

            <ListView.Resources>
                <ControlTemplate x:Key="ItemTemplate" TargetType='{x:Type ListViewItem}'>
                    <StackPanel Background="Beige">
                        <GridViewRowPresenter Margin="0,0,0,2" Content="{TemplateBinding Content}"
                                Columns="{TemplateBinding GridView.ColumnCollection}"/>                        
                    </StackPanel>
                </ControlTemplate>
            </ListView.Resources>
            
			<ListView.ItemContainerStyle>
				<Style TargetType="ListViewItem">
					<Setter Property="HorizontalAlignment" Value="Stretch" />
					<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
					<Setter Property="VerticalContentAlignment" Value="Top"/>
                    <Setter Property="Template"  Value="{StaticResource ItemTemplate}"/>
				</Style>
			</ListView.ItemContainerStyle>
			<ListView.GroupStyle>
				<GroupStyle ContainerStyle="{StaticResource ListGroupStyle}">
				</GroupStyle>
			</ListView.GroupStyle>				
		</ListView>
		
		<Popup x:Name="PopupNotifications" Placement="Center" PlacementTarget="{Binding ElementName=ListOfSimulatedClasses}" 
			   IsOpen="{Binding Path=EngineMessages.ShowEngineMessages}">
			<local:EngineNotifications x:Name="Notifications"  DataContext="{Binding Path=EngineMessages}"></local:EngineNotifications>
		</Popup>
	</Grid>	   
</UserControl>